import glob
import SCons.Script
import os
import sys

flags = [ "-Wall", "-O0","-ggdb","-fasm-blocks","-msse3"]

dirnames = ["util","geom","algebra", "glutil", "tests","forestengine","dataengine","dataengine/shapelib","dataengine/voronoi","plugengine","UnitTest++/src","UnitTest++/src/POSIX"]

dirs = map(lambda x:'src/'+x+'/*.cpp',dirnames)

files = []                                

for dir in  dirs:
    files = files+glob.glob(dir)

libraries = Split('''
      ''');


all_args = sys.argv[1:]

env = Environment(ENV = os.environ)
env.Append (LINKFLAGS = ['-framework', 'OpenGL']) 

testEnv = Environment(ENV = os.environ)
testEnv.Append (LINKFLAGS = ['-framework', 'OpenGL']) 

env.BuildDir('build/vibos','.',duplicate=0)
testEnv.BuildDir('build/tests','.',duplicate=0)

mainFiles = map(lambda x:'build/vibos/'+x, files)
testFiles = map(lambda x:'build/tests/'+x, files)

env.Program("vibos",
      mainFiles+['src/vibosmain.cpp'], 
      CPPPATH = [ "#inc", "src"],
      CXXFLAGS = flags,
      LIBS = libraries
)


testEnv.Program("testvibos",
      testFiles+['src/testsmain.cpp'], 
      CPPPATH = [ "#inc", "src"],
      CXXFLAGS = flags,
      LIBS = libraries
)

if ('run' in COMMAND_LINE_TARGETS):
   env.Command("run","vibos",'./vibos')

if ('test' in COMMAND_LINE_TARGETS):
   env.Command("test","testvibos", "./testvibos")


if ('testrun' in COMMAND_LINE_TARGETS):
   env.Command("testrun",["testvibos","vibos"],'./testvibos&&./vibos')

if('doc' in COMMAND_LINE_TARGETS):
    env.Command("doc",["testvibos","vibos"],'doxygen doxygen.cfg')
